package com.stox.ui.swing.widget.wrapper;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

import com.stox.model.AbstractModel;

public class DefaultTreeCellRenderer extends javax.swing.tree.DefaultTreeCellRenderer {
	private static final long serialVersionUID = 1L;

	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value,
			boolean selected, boolean expanded, boolean leaf, int row,
			boolean hasFocus) {
		
		if(value instanceof DefaultMutableTreeNode) {
			Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
			if(userObject instanceof AbstractModel) {
				AbstractModel model = (AbstractModel)userObject;
				value = model.getName();
			}
		}
		
		return super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
	}

}
